import Vue from 'vue'

import Msg from './msg.vue'

let MsgContructor = Vue.extend(Msg);

class MsgClass{
    static dialog(option){
        let msg = typeof option === 'string' ? option : option.message;
        let type = typeof option === 'string' ? '' : option.type;
        if(!MsgClass.instance){
            MsgClass.instance = new MsgContructor({
                el:document.createElement('div')
            })

            document.body.appendChild(MsgClass.instance.$el)
        }

        MsgClass.instance.msg = msg;
        MsgClass.instance.type = type;
        MsgClass.instance.isShow = true;

        if(MsgClass.instance.timer){
            clearTimeout(MsgClass.instance.timer)
        }

        MsgClass.instance.timer = setTimeout(() => {
            MsgClass.instance.isShow = false;
        },3000)

        return MsgClass.instance
    }
}

export default MsgClass

